package TetrisFlash.GameLoadData 
{
	import flash.media.SoundChannel;
	import flash.media.Sound;
	/**
	 * ...
	 * @author DANTRUONG
	 */
	public class SoundManager 
	{
		public static const SOUND_ADDBRICK:int = 0;
		public static const SOUND_BACKGAME:int = 1;
		public static const SOUND_BACKMENU:int = 2;
		public static const SOUND_CHOOSE:int = 3;
		public static const SOUND_COOL:int = 4;
		public static const SOUND_GOOD:int = 5;
		public static const SOUND_GREAT:int = 6;
		public static const SOUND_LOST:int = 7;
		public static const SOUND_PERFECT:int = 8;
		public static const SOUND_WIN:int = 9;
		
		[Embed(source = "/../media/sounds/addbrick.mp3")]
		private var Sound_AddBrick:Class;
		
		[Embed(source = "/../media/sounds/backgame.mp3")]
		private var Sound_BackGame:Class;
		
		[Embed(source = "/../media/sounds/backmenu.mp3")]
		private var Sound_BackMenu:Class;
		
		[Embed(source = "/../media/sounds/chose.mp3")]
		private var Sound_Choose:Class;
		
		[Embed(source = "/../media/sounds/cool.mp3")]
		private var Sound_Cool:Class;
		
		[Embed(source = "/../media/sounds/good.mp3")]
		private var Sound_Good:Class;
		
		[Embed(source = "/../media/sounds/great.mp3")]
		private var Sound_Great:Class;
		
		[Embed(source = "/../media/sounds/lost.mp3")]
		private var Sound_Lost:Class;
		
		[Embed(source = "/../media/sounds/perffect.mp3")]
		private var Sound_Perfect:Class;
		
		[Embed(source = "/../media/sounds/win.mp3")]
		private var Sound_Win:Class;
		
		private var chanelSoundEffect:SoundChannel;
		private var chanelSoundBackMenu:SoundChannel;
		private var chanelSoundBackGame:SoundChannel;
		private var soundList:Vector.<Sound>;
		
		private static var instance: SoundManager;
		
		public static function getInstance():SoundManager {
			if (!instance) {
				instance = new SoundManager();
			}
			
			return instance;
		}
		
		public function SoundManager() {
			soundList = new Vector.<Sound>;
			soundList.push(new Sound_AddBrick(), new Sound_BackGame(),
			new Sound_BackMenu(), new Sound_Choose(), new Sound_Cool(),
			new Sound_Good(), new Sound_Great(), new Sound_Lost(), new Sound_Perfect(),
			new Sound_Win());
		}
		
		public function playBackSoundMenu():void {
			chanelSoundBackMenu = soundList[SOUND_BACKMENU].play();
		}
		
		public function stopBackSoundMenu():void {
			if (chanelSoundBackMenu) {
				chanelSoundBackMenu.stop();
			}
		}
		
		public function playBackSoundGame():void {
			chanelSoundBackGame = soundList[SOUND_BACKGAME].play();
		}
		
		public function stopBackSoundGame():void {
			if (chanelSoundBackGame) {
				chanelSoundBackGame.stop();
			}
		}
		
		public function play(type: int):void {
			if (type > soundList.length - 1) {
				return;
			}
			chanelSoundEffect = soundList[type].play();
		}
		
		public function stop(): void {
			if (chanelSoundEffect) {
				chanelSoundEffect.stop();
			}
		}
		
		public function ReleaseSoundManager():void {
			soundList = null;
			chanelSoundEffect = null;
			chanelSoundBackMenu = null;
			chanelSoundBackGame = null;
		}
	}

}